<?php

use app\components\BaseGridView;
use app\helpers\UserHelper;
use app\models\Group;
use app\models\User;
use yii\helpers\ArrayHelper;
use yii\helpers\Html;
use yii\helpers\Url;

/* @var $dataProvider */

?>

<div class="mb-2">
    <?= Html::a('添加组', ['save'], ['class' => 'btn dialog', 'title' => '添加组']); ?>

    <div class="search pull-right">
        <form class="form-inline" action="/index.php" method="get">
            <input type="hidden" name="r" value="group/index">
            <div class="form-group">
                <label>组号</label>
                <input type="text" value="<?= Yii::$app->request->get('group_num') ?>" name="group_num" class="form-control">
            </div>
            <button type="button" class="btn btn-info btn-search">搜索</button>
        </form>
    </div>
</div>

<?= BaseGridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => NULL,
    'columns' => [
        'group_num',
        ['attribute' => 'group_type', 'value' => function(Group $model){
            return ArrayHelper::getValue(UserHelper::$groupType, $model['group_type']);
        }],
        ['attribute' => 'group_priority', 'value' => function(Group $model){
            return ArrayHelper::getValue(UserHelper::$userPriority, $model['group_priority']);
        }],
        'create_time:datetime',
        [
            'class' => 'app\components\BaseActionColumn',
            'template' => '{view} {save} {delete} {save-user} {group-user}',
            'contentOptions' => ['width' => '18%'],
            'buttons' => [
                'view' => function ($url, $model, $key) {
                    $options = [
                        'title' => '查看组信息',
                        'data-toggle' => 'tooltip',
                        'class' => 'dialog'
                    ];
                    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
                },
                'save-user' => function ($url, $model, $key) {
                    $options = [
                        'title' => '添加组成员',
                        'data-toggle' => 'tooltip',
                        'class' => 'dialog'
                    ];
                    $params = is_array($key) ? $key : ['group_num' => (string) $key];
                    $params[0] = 'group-user/save';
                    $url = Url::to($params);
                    return Html::a('<span class="glyphicon glyphicon-plus-sign"></span>', $url, $options);
                },
                'group-user' => function ($url, $model, $key) {
                    $options = [
                        'title' => '查看组成员',
                        'data-toggle' => 'tooltip',
                        'class' => 'dialog'
                    ];
                    $params = is_array($key) ? $key : ['group_num' => (string) $key];
                    $params[0] = 'group-user/index';
                    $url = Url::to($params);
                    return Html::a('<span class="glyphicon glyphicon-eye-open"></span>', $url, $options);
                },
            ]
        ]
    ],
]); ?>
